package users

import (
	"go_auth/ext/settings"
	"go_auth/utils/commons"
)

/**
用户角色信息

角色添加这块以后加上验证
#todo
*/

type Role struct {
	RoleId   int    `xorm:" int(4)  pk  notnull unique autoincr 'role_id'"`
	RoleName string `xorm:" varchar(200) 'role_name'"`
}

func (role *Role) AddRole() int64 {
	insert, err := settings.MasterDB.Insert(role)
	if commons.CheckErr(err) {
		return insert
	}
	return settings.Zero
}

func (role *Role) UpdateRole() int64 {
	affected, err := settings.MasterDB.Id(role.RoleId).Update(role)
	if commons.CheckErr(err) {
		return affected
	}
	return settings.Zero
}

func (role *Role) DeleteRole() int64 {
	affected, err := settings.MasterDB.Id(role.RoleId).Delete(role)
	if commons.CheckErr(err) {
		return affected
	}
	return settings.Zero
}

func FindRoles() interface{} {
	role := make([]Role, 0)
	find := settings.MasterDB.Find(&role)
	if !commons.CheckErr(find) {
		return nil
	}
	return role
}

//TODO
func FindRoleName() {

}
